﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace ScarEngine
{
    public class DefaultLevel:Level
    {
        public int row;

        public override void Init() // Called at the very start
        {

            row = 1;
            base.Init();
        }

        public override void ContentLoad() // Called when loading content
        {
            LoadTexture("OnePixelWhite");
            LoadTexture("Creature");
            LoadTexture("Circle", "DefaultCircle");
            LoadFont("Arial");
            LoadFont("ScarText");
            LoadFont("Credit");
            base.ContentLoad();
        }

        public override void BeginRun() // Called right before the first update runs
        {


            MasterManager.GraphicsManager.SetResolution(1024, 768);

            TextObject T = new TextObject();
            PositionalComponent P = T.Get<PositionalComponent>();
            TextComponent TEXT = T.Get<TextComponent>();

            //P.Position = new Vector2(725,725);
            P.Position = new Vector2(0, 0);
            TEXT.Font = GetFont("ScarText");
            TEXT.Text = "Scar Gaming Engine";
            TEXT.Color = new Color(255, 0, 0, 255);


            TextObject C = new TextObject();
            PositionalComponent PC = C.Get<PositionalComponent>();
            TextComponent TC = C.Get<TextComponent>();
            PC.Position = new Vector2(755, 745);
            TC.Font = GetFont("Credit");
            TC.Text = "Copyright 2011 Zachary Nawar";
            TC.Color = new Color(10, 255, 0, 255);

            VelocityObject V = new VelocityObject();
            V.Add<DrawableComponent>("Drawable");
            V.Add<PhysicsComponent>("Physics");
            DrawableComponent D = V.Get<DrawableComponent>();
            D.Texture = GetTexture("DefaultCircle");
            D.Scale = 0.25f;
            PhysicsComponent PH = V.Get<PhysicsComponent>();
            PH.Gravity = true;
            PH.Mass = 10;
            P = V.Get<PositionalComponent>();
            VelocityComponent VC = V.Get<VelocityComponent>();
            P.Position = new Vector2(150, 750);
            VC.Angle = MathHelper.Pi - 0.0005f;

            VC.Velocity = 200;

            base.BeginRun();
        }

        public override void Update(GameTime gameTime) // Called on Update
        {


            //DrawableObject A = new DrawableObject();
            //PositionalComponent B = A.Get<PositionalComponent>();
            //B.Position = new Vector2(0, row - 10);

            //foreach (GameObject gameObject in MasterManager.GameObjects)
            //{
            //    if (gameObject.GetType() == typeof(DrawableObject))
            //    {
            //        PositionalComponent P = gameObject.Get<PositionalComponent>();
            //        P.Position = P.Position + new Vector2(40, 0);
            //        if (P.Position.X >= MasterManager.GraphicsManager.graphics.GraphicsDevice.Viewport.Width)
            //        {
            //            row += 1;
            //            P.Position = P.Position - new Vector2(P.Position.X, 0);
            //        }
            //        if (P.Position.Y >= MasterManager.GraphicsManager.graphics.GraphicsDevice.Viewport.Height)
            //        {
            //            gameObject.Delete();
            //        }
            //    }
            //}

            
            
            base.Update(gameTime);
        }



    }

}